﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using VisionConfig;


namespace FalionForm
{
    /// <summary>
    /// MainPage.xaml 的交互逻辑
    /// </summary>
    public partial class MainPage : Page
    {
       
        public _DisPlay _dp = new _DisPlay();
        public MainPage()
        {
            InitializeComponent();
            this.Display.Child = _dp;
            pro = new Process();
            Process.hWindowID = _dp.window1;
            Process.HDC = _dp.HDC;
            pro.mp = this;
            MainWindow.SClient.Connect();

            Run(new object(),new RoutedEventArgs());
        }
        public static Process pro;

        private void OnlyDispCold(object sender, RoutedEventArgs e)
        {
            Process.OnlyCold = (bool)onlycold.IsChecked;
            if ((bool)disp2d.IsChecked)
            {
                disp2d.IsChecked = false;
            }
        }
        private void Disp2D(object sender, RoutedEventArgs e)
        {
            Process.Disp2D = (bool)disp2d.IsChecked;
            if ((bool)onlycold.IsChecked)
            {
                onlycold.IsChecked = false;
            }
        }
        private void SaveImg(object sender, RoutedEventArgs e)
        {
            Process.IsSaveImg = (bool)saveimg.IsChecked;
        }
        private void OffLine(object sender, RoutedEventArgs e)
        {
            Process.OffLine = (bool)off.IsChecked;
        }


        private void Run(object sender, RoutedEventArgs e)
        {
            lis.IsEnabled = false;
            RunContinue.IsEnabled = false;
            runOnceButton.IsEnabled = false;
            pro.AutoFlg = true;
            
            pro.RunTime = 0;
        }
        private void Stop(object sender, RoutedEventArgs e)
        {
            lis.IsEnabled = true;
            runOnceButton.IsEnabled = true;
            RunContinue.IsEnabled = true;
            pro.AutoFlg = false;
            pro.RunTime = 0;
        }
        private void RunOnce(object sender, RoutedEventArgs e)
        {
            runOnceButton.IsEnabled = false;
           // pro.Raction();
            Th = new Thread(new ThreadStart(Run));
            Th.IsBackground = true;
            Th.Start();          
        }
        Thread Th;

        string[] Strl = new string[10];

        void Run()
        {
            pro.Raction(Strl);
            this.Dispatcher.Invoke(new Action(() => {
                runOnceButton.IsEnabled = true;
            }));
            
        }

        public void DispInfomation(HTuple inf)
        {
            if (inf.Length<7)
            {
                return;
            }
            this.Dispatcher.Invoke(new Action(() => {

                AxisX.Text = inf[0].D.ToString("f2");
                AxisY.Text = inf[1].D.ToString("f2");
                AxisZ.Text = inf[2].D.ToString("f2");
                AngleX.Text = inf[3].D.ToString("f2");
                AngleY.Text = inf[4].D.ToString("f2");
                AngleZ.Text = inf[5].D.ToString("f2");
                Scort.Text = inf[6].D.ToString("f2");
            }));
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            pro.CaliAngle();
        }

 
    }
}
